{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "52b4b3e8-7e35-4d0e-9b24-98bd4bad8fd1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl\n",
    "from perspective.widget import PerspectiveWidget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "15e96704-33ea-4f43-bd4e-48540814cd01",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = pl.read_parquet(\"new_share.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3edeaa09-fc1c-404e-a2a0-9dfb168feeef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (2_000, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>ts_code</th><th>sub_code</th><th>name</th><th>ipo_date</th><th>issue_date</th><th>amount</th><th>market_amount</th><th>price</th><th>pe</th><th>limit_amount</th><th>funds</th><th>ballot</th></tr><tr><td>str</td><td>str</td><td>str</td><td>date</td><td>date</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;001390.SZ&quot;</td><td>&quot;001390&quot;</td><td>&quot;古麒绒材&quot;</td><td>2025-05-19</td><td>null</td><td>5000.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>2.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;603014.SH&quot;</td><td>&quot;732014&quot;</td><td>&quot;威高血净&quot;</td><td>2025-05-08</td><td>null</td><td>4114.0</td><td>2685.0</td><td>26.5</td><td>24.82</td><td>1.1</td><td>10.902</td><td>0.03</td></tr><tr><td>&quot;301595.SZ&quot;</td><td>&quot;301595&quot;</td><td>&quot;太力科技&quot;</td><td>2025-05-08</td><td>null</td><td>2707.0</td><td>1178.0</td><td>17.05</td><td>21.55</td><td>0.65</td><td>4.615</td><td>0.02</td></tr><tr><td>&quot;688755.SH&quot;</td><td>&quot;787755&quot;</td><td>&quot;汉邦科技&quot;</td><td>2025-05-07</td><td>null</td><td>2200.0</td><td>704.0</td><td>22.77</td><td>26.35</td><td>0.5</td><td>5.009</td><td>0.03</td></tr><tr><td>&quot;301636.SZ&quot;</td><td>&quot;301636&quot;</td><td>&quot;泽润新能&quot;</td><td>2025-04-28</td><td>null</td><td>1597.0</td><td>774.0</td><td>33.06</td><td>17.57</td><td>0.45</td><td>5.279</td><td>0.02</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;300776.SZ&quot;</td><td>&quot;300776&quot;</td><td>&quot;帝尔激光&quot;</td><td>2019-05-07</td><td>2019-05-17</td><td>1654.0</td><td>1654.0</td><td>57.71</td><td>22.99</td><td>1.6</td><td>9.543</td><td>0.01</td></tr><tr><td>&quot;300777.SZ&quot;</td><td>&quot;300777&quot;</td><td>&quot;中简科技&quot;</td><td>2019-05-06</td><td>2019-05-16</td><td>4001.0</td><td>3601.0</td><td>6.06</td><td>22.98</td><td>1.1</td><td>2.425</td><td>0.04</td></tr><tr><td>&quot;603267.SH&quot;</td><td>&quot;732267&quot;</td><td>&quot;鸿远电子&quot;</td><td>2019-04-30</td><td>2019-05-15</td><td>4134.0</td><td>3721.0</td><td>20.24</td><td>16.5</td><td>1.6</td><td>8.367</td><td>0.03</td></tr><tr><td>&quot;600989.SH&quot;</td><td>&quot;730989&quot;</td><td>&quot;宝丰能源&quot;</td><td>2019-04-30</td><td>2019-05-16</td><td>73336.0</td><td>66002.0</td><td>11.12</td><td>22.07</td><td>22.0</td><td>81.55</td><td>0.25</td></tr><tr><td>&quot;300778.SZ&quot;</td><td>&quot;300778&quot;</td><td>&quot;新城市&quot;</td><td>2019-04-25</td><td>2019-05-10</td><td>2000.0</td><td>2000.0</td><td>27.33</td><td>22.99</td><td>2.0</td><td>5.466</td><td>0.02</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (2_000, 12)\n",
       "┌───────────┬──────────┬──────────┬────────────┬───┬───────┬──────────────┬────────┬────────┐\n",
       "│ ts_code   ┆ sub_code ┆ name     ┆ ipo_date   ┆ … ┆ pe    ┆ limit_amount ┆ funds  ┆ ballot │\n",
       "│ ---       ┆ ---      ┆ ---      ┆ ---        ┆   ┆ ---   ┆ ---          ┆ ---    ┆ ---    │\n",
       "│ str       ┆ str      ┆ str      ┆ date       ┆   ┆ f64   ┆ f64          ┆ f64    ┆ f64    │\n",
       "╞═══════════╪══════════╪══════════╪════════════╪═══╪═══════╪══════════════╪════════╪════════╡\n",
       "│ 001390.SZ ┆ 001390   ┆ 古麒绒材 ┆ 2025-05-19 ┆ … ┆ 0.0   ┆ 2.0          ┆ 0.0    ┆ 0.0    │\n",
       "│ 603014.SH ┆ 732014   ┆ 威高血净 ┆ 2025-05-08 ┆ … ┆ 24.82 ┆ 1.1          ┆ 10.902 ┆ 0.03   │\n",
       "│ 301595.SZ ┆ 301595   ┆ 太力科技 ┆ 2025-05-08 ┆ … ┆ 21.55 ┆ 0.65         ┆ 4.615  ┆ 0.02   │\n",
       "│ 688755.SH ┆ 787755   ┆ 汉邦科技 ┆ 2025-05-07 ┆ … ┆ 26.35 ┆ 0.5          ┆ 5.009  ┆ 0.03   │\n",
       "│ 301636.SZ ┆ 301636   ┆ 泽润新能 ┆ 2025-04-28 ┆ … ┆ 17.57 ┆ 0.45         ┆ 5.279  ┆ 0.02   │\n",
       "│ …         ┆ …        ┆ …        ┆ …          ┆ … ┆ …     ┆ …            ┆ …      ┆ …      │\n",
       "│ 300776.SZ ┆ 300776   ┆ 帝尔激光 ┆ 2019-05-07 ┆ … ┆ 22.99 ┆ 1.6          ┆ 9.543  ┆ 0.01   │\n",
       "│ 300777.SZ ┆ 300777   ┆ 中简科技 ┆ 2019-05-06 ┆ … ┆ 22.98 ┆ 1.1          ┆ 2.425  ┆ 0.04   │\n",
       "│ 603267.SH ┆ 732267   ┆ 鸿远电子 ┆ 2019-04-30 ┆ … ┆ 16.5  ┆ 1.6          ┆ 8.367  ┆ 0.03   │\n",
       "│ 600989.SH ┆ 730989   ┆ 宝丰能源 ┆ 2019-04-30 ┆ … ┆ 22.07 ┆ 22.0         ┆ 81.55  ┆ 0.25   │\n",
       "│ 300778.SZ ┆ 300778   ┆ 新城市   ┆ 2019-04-25 ┆ … ┆ 22.99 ┆ 2.0          ┆ 5.466  ┆ 0.02   │\n",
       "└───────────┴──────────┴──────────┴────────────┴───┴───────┴──────────────┴────────┴────────┘"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "11bd644b-3d7d-44f1-bec4-1157222cd75e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (5_412, 17)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>ts_code</th><th>symbol</th><th>name</th><th>area</th><th>industry</th><th>fullname</th><th>enname</th><th>cnspell</th><th>market</th><th>exchange</th><th>curr_type</th><th>list_status</th><th>list_date</th><th>delist_date</th><th>is_hs</th><th>act_name</th><th>act_ent_type</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>date</td><td>null</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;000001.SZ&quot;</td><td>&quot;000001&quot;</td><td>&quot;平安银行&quot;</td><td>&quot;深圳&quot;</td><td>&quot;银行&quot;</td><td>&quot;平安银行股份有限公司&quot;</td><td>&quot;Ping An Bank Co., Ltd.&quot;</td><td>&quot;payh&quot;</td><td>&quot;主板&quot;</td><td>&quot;SZSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>1991-04-03</td><td>null</td><td>&quot;S&quot;</td><td>&quot;无实际控制人&quot;</td><td>&quot;无&quot;</td></tr><tr><td>&quot;000002.SZ&quot;</td><td>&quot;000002&quot;</td><td>&quot;万科A&quot;</td><td>&quot;深圳&quot;</td><td>&quot;全国地产&quot;</td><td>&quot;万科企业股份有限公司&quot;</td><td>&quot;China Vanke Co.,Ltd.&quot;</td><td>&quot;wka&quot;</td><td>&quot;主板&quot;</td><td>&quot;SZSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>1991-01-29</td><td>null</td><td>&quot;S&quot;</td><td>&quot;深圳市人民政府国有资产监督管理委员会&quot;</td><td>&quot;地方国企&quot;</td></tr><tr><td>&quot;000004.SZ&quot;</td><td>&quot;000004&quot;</td><td>&quot;*ST国华&quot;</td><td>&quot;深圳&quot;</td><td>&quot;软件服务&quot;</td><td>&quot;深圳国华网安科技股份有限公司&quot;</td><td>&quot;Shenzhen Guohua Network Securi…</td><td>&quot;stgh&quot;</td><td>&quot;主板&quot;</td><td>&quot;SZSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>1991-01-14</td><td>null</td><td>&quot;N&quot;</td><td>&quot;李映彤&quot;</td><td>&quot;民营企业&quot;</td></tr><tr><td>&quot;000006.SZ&quot;</td><td>&quot;000006&quot;</td><td>&quot;深振业A&quot;</td><td>&quot;深圳&quot;</td><td>&quot;区域地产&quot;</td><td>&quot;深圳市振业(集团)股份有限公司&quot;</td><td>&quot;Shenzhen Zhenye(Group) Co., Lt…</td><td>&quot;szya&quot;</td><td>&quot;主板&quot;</td><td>&quot;SZSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>1992-04-27</td><td>null</td><td>&quot;S&quot;</td><td>&quot;深圳市人民政府国有资产监督管理委员会&quot;</td><td>&quot;地方国企&quot;</td></tr><tr><td>&quot;000007.SZ&quot;</td><td>&quot;000007&quot;</td><td>&quot;全新好&quot;</td><td>&quot;深圳&quot;</td><td>&quot;其他商业&quot;</td><td>&quot;深圳市全新好股份有限公司&quot;</td><td>&quot;Shenzhen Quanxinhao Co,.Ltd.&quot;</td><td>&quot;qxh&quot;</td><td>&quot;主板&quot;</td><td>&quot;SZSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>1992-04-13</td><td>null</td><td>&quot;N&quot;</td><td>&quot;王玩虹&quot;</td><td>&quot;民营企业&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;920489.BJ&quot;</td><td>&quot;920489&quot;</td><td>&quot;佳先股份&quot;</td><td>null</td><td>null</td><td>&quot;安徽佳先功能助剂股份有限公司&quot;</td><td>&quot;Anhui Jiaxian Functional Auxil…</td><td>&quot;jxgf&quot;</td><td>&quot;北交所&quot;</td><td>&quot;BSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>2020-07-27</td><td>null</td><td>&quot;N&quot;</td><td>null</td><td>null</td></tr><tr><td>&quot;920682.BJ&quot;</td><td>&quot;920682&quot;</td><td>&quot;球冠电缆&quot;</td><td>null</td><td>null</td><td>&quot;宁波球冠电缆股份有限公司&quot;</td><td>&quot;Ningbo Qrunning Cable Co.,Ltd&quot;</td><td>&quot;qgdl&quot;</td><td>&quot;北交所&quot;</td><td>&quot;BSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>2020-07-27</td><td>null</td><td>&quot;N&quot;</td><td>null</td><td>null</td></tr><tr><td>&quot;920799.BJ&quot;</td><td>&quot;920799&quot;</td><td>&quot;艾融软件&quot;</td><td>null</td><td>null</td><td>&quot;上海艾融软件股份有限公司&quot;</td><td>&quot;Shanghai I2finance Technology …</td><td>&quot;arrj&quot;</td><td>&quot;北交所&quot;</td><td>&quot;BSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>2020-07-27</td><td>null</td><td>&quot;N&quot;</td><td>null</td><td>null</td></tr><tr><td>&quot;920819.BJ&quot;</td><td>&quot;920819&quot;</td><td>&quot;颖泰生物&quot;</td><td>null</td><td>null</td><td>&quot;北京颖泰嘉和生物科技股份有限公司&quot;</td><td>&quot;Nutrichem Company Limited&quot;</td><td>&quot;ytsw&quot;</td><td>&quot;北交所&quot;</td><td>&quot;BSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>2020-07-27</td><td>null</td><td>&quot;N&quot;</td><td>null</td><td>null</td></tr><tr><td>&quot;689009.SH&quot;</td><td>&quot;689009&quot;</td><td>&quot;九号公司-WD&quot;</td><td>&quot;北京&quot;</td><td>&quot;摩托车&quot;</td><td>&quot;九号有限公司&quot;</td><td>&quot;Ninebot Limited&quot;</td><td>&quot;jhgs&quot;</td><td>&quot;科创板&quot;</td><td>&quot;SSE&quot;</td><td>&quot;CNY&quot;</td><td>&quot;L&quot;</td><td>2020-10-29</td><td>null</td><td>null</td><td>null</td><td>null</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (5_412, 17)\n",
       "┌───────────┬────────┬─────────────┬──────┬───┬─────────────┬───────┬─────────────────────────────────┬──────────────┐\n",
       "│ ts_code   ┆ symbol ┆ name        ┆ area ┆ … ┆ delist_date ┆ is_hs ┆ act_name                        ┆ act_ent_type │\n",
       "│ ---       ┆ ---    ┆ ---         ┆ ---  ┆   ┆ ---         ┆ ---   ┆ ---                             ┆ ---          │\n",
       "│ str       ┆ str    ┆ str         ┆ str  ┆   ┆ null        ┆ str   ┆ str                             ┆ str          │\n",
       "╞═══════════╪════════╪═════════════╪══════╪═══╪═════════════╪═══════╪═════════════════════════════════╪══════════════╡\n",
       "│ 000001.SZ ┆ 000001 ┆ 平安银行    ┆ 深圳 ┆ … ┆ null        ┆ S     ┆ 无实际控制人                    ┆ 无           │\n",
       "│ 000002.SZ ┆ 000002 ┆ 万科A       ┆ 深圳 ┆ … ┆ null        ┆ S     ┆ 深圳市人民政府国有资产监督管理  ┆ 地方国企     │\n",
       "│           ┆        ┆             ┆      ┆   ┆             ┆       ┆ 委员会                          ┆              │\n",
       "│ 000004.SZ ┆ 000004 ┆ *ST国华     ┆ 深圳 ┆ … ┆ null        ┆ N     ┆ 李映彤                          ┆ 民营企业     │\n",
       "│ 000006.SZ ┆ 000006 ┆ 深振业A     ┆ 深圳 ┆ … ┆ null        ┆ S     ┆ 深圳市人民政府国有资产监督管理  ┆ 地方国企     │\n",
       "│           ┆        ┆             ┆      ┆   ┆             ┆       ┆ 委员会                          ┆              │\n",
       "│ 000007.SZ ┆ 000007 ┆ 全新好      ┆ 深圳 ┆ … ┆ null        ┆ N     ┆ 王玩虹                          ┆ 民营企业     │\n",
       "│ …         ┆ …      ┆ …           ┆ …    ┆ … ┆ …           ┆ …     ┆ …                               ┆ …            │\n",
       "│ 920489.BJ ┆ 920489 ┆ 佳先股份    ┆ null ┆ … ┆ null        ┆ N     ┆ null                            ┆ null         │\n",
       "│ 920682.BJ ┆ 920682 ┆ 球冠电缆    ┆ null ┆ … ┆ null        ┆ N     ┆ null                            ┆ null         │\n",
       "│ 920799.BJ ┆ 920799 ┆ 艾融软件    ┆ null ┆ … ┆ null        ┆ N     ┆ null                            ┆ null         │\n",
       "│ 920819.BJ ┆ 920819 ┆ 颖泰生物    ┆ null ┆ … ┆ null        ┆ N     ┆ null                            ┆ null         │\n",
       "│ 689009.SH ┆ 689009 ┆ 九号公司-WD ┆ 北京 ┆ … ┆ null        ┆ null  ┆ null                            ┆ null         │\n",
       "└───────────┴────────┴─────────────┴──────┴───┴─────────────┴───────┴─────────────────────────────────┴──────────────┘"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7b368e8b-df2e-48b6-a88c-906f05325397",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7efd1dbefe32460fa9510b794bfee967",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "PerspectiveWidget(binding_mode='server', columns=['index', 'ts_code', 'sub_code', 'name', 'ipo_date', 'issue_d…"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import polars as pl\n",
    "from perspective import PerspectiveWidget\n",
    "\n",
    "# 假设 d1 是你的 Polars DataFrame\n",
    "# 先将日期列转换为字符串（可选）\n",
    "d1 = d1.with_columns(\n",
    "    pl.col(\"ipo_date\").cast(pl.Utf8).alias(\"ipo_date_str\")\n",
    ")\n",
    "\n",
    "# 转换为 Pandas DataFrame\n",
    "pandas_df = d1.to_pandas()\n",
    "\n",
    "# 使用 Pandas DataFrame 创建 PerspectiveWidget\n",
    "widget = PerspectiveWidget(pandas_df)\n",
    "widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ae178396-0863-40ce-83fd-2743775d0466",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "polars.dataframe.frame.DataFrame"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7b9f52ce-1cfb-4dfe-b2f2-4355b5086ce4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2404cb3dc83d4ff6ab494848958c2358",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "PerspectiveWidget(binding_mode='server', columns=['index', 'ts_code', 'symbol', 'name', 'area', 'industry', 'f…"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将所有列转换为字符串类型\n",
    "d2_str = d2.select([pl.col(column).cast(pl.Utf8).alias(column) for column in d2.columns])\n",
    "\n",
    "# 再转换为 Pandas DataFrame\n",
    "pandas_df = d2_str.to_pandas()\n",
    "\n",
    "# 使用 PerspectiveWidget 加载\n",
    "widget = PerspectiveWidget(pandas_df)\n",
    "widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1b779d3-6a33-4343-bc4e-468ed882a555",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
